package kr.inani.android.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.util.AttributeSet;
import android.widget.EditText;

public class CustomEditText extends EditText {

	public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public CustomEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public CustomEditText(Context context) {
		super(context);
	}

    public void setHint(CharSequence hintText, Drawable hintDrawable) {
        setHint(getDecoratedHint(hintText, hintDrawable));
    }
    
    private CharSequence getDecoratedHint(CharSequence hintText, Drawable hintDrawable) {
        SpannableStringBuilder ssb = new SpannableStringBuilder(hintText);
        ssb.append("                    ");
		hintDrawable.setBounds(0, 0, hintDrawable.getIntrinsicWidth(), hintDrawable.getIntrinsicHeight());
		ssb.setSpan(new ImageSpan(hintDrawable), hintText.length(), hintText.length()+20, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        return ssb;
    }
    
}
